/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulateurs.view.controllersView;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;

/**
 *
 * @author Lunesco
 */
public class RoundButton extends JButton {
    
    public RoundButton(String label, double x, double y, double diametre) {
        super(label);
        int absci=(int)x;
        int ordon=(int)y;
        int diam=(int)diametre;
        Dimension size = new Dimension(diam, diam); // modif jordan, longeur et largeur !
        this.setPreferredSize(size);
        this.setLocation(absci-diam/2, ordon-diam/2);
        setContentAreaFilled(false);
    }
    
    protected void paintComponent(Graphics g) {
        if (getModel().isArmed()) {
            g.setColor(Color.lightGray);
        } else {
            g.setColor(getBackground());
        }
        g.fillOval(0, 0, getSize().width-1, getSize().height-1);
        super.paintComponent(g);
    }
    
    
//    @Override
//    protected void paintBorder(Graphics g) {
//        g.setColor(getBackground().darker());
//        g.drawOval(0, 0, getSize().width-1, getSize().height-1);
//    }
    
    private Shape shape;
    
    public boolean contains(int x, int y) {
        if (shape == null || !shape.getBounds().equals(getBounds())) {
            shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
        }
        return shape.contains(x, y);
    }
}
